<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  
  <meta name="google-site-verification" content="k9iQUbEI9rWq3xYeh63ATztKdkthC4dNRHV_25maJ3Q" />
  <title>vim学习笔记 | Taylor&#39;s Learning Diary</title>
  <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
  <meta name="description" content="还是要经常折腾一下  最近稍微折腾了一下vim，大家都知道linux环境下如果vim操作的足够熟练，完全可以替代各种文本编辑器，然而自己对vim的操作仍停留在最原始和基础的命令，只会简单的增删改查，比如删除d，进入编辑模式i，复制粘贴y&amp;amp;p，代码上下翻阅左右箭头，看到这你估计都惊呆了，怎么这么low!也是由于近期经常需要到仿真机上修改代码，发现自己vim编辑效率超级低，这才想着好好过一遍">
<meta name="keywords" content="linux,vim">
<meta property="og:type" content="article">
<meta property="og:title" content="vim学习笔记">
<meta property="og:url" content="https://upeng.github.io/blog/2016/09/11/vim/index.html">
<meta property="og:site_name" content="Taylor&#39;s Learning Diary">
<meta property="og:description" content="还是要经常折腾一下  最近稍微折腾了一下vim，大家都知道linux环境下如果vim操作的足够熟练，完全可以替代各种文本编辑器，然而自己对vim的操作仍停留在最原始和基础的命令，只会简单的增删改查，比如删除d，进入编辑模式i，复制粘贴y&amp;amp;p，代码上下翻阅左右箭头，看到这你估计都惊呆了，怎么这么low!也是由于近期经常需要到仿真机上修改代码，发现自己vim编辑效率超级低，这才想着好好过一遍">
<meta property="og:locale" content="zh-CN">
<meta property="og:image" content="https://raw.githubusercontent.com/upeng/upeng.github.io/master/image/vim-keyboard.png">
<meta property="og:updated_time" content="2017-09-28T15:07:00.739Z">
<meta name="twitter:card" content="summary">
<meta name="twitter:title" content="vim学习笔记">
<meta name="twitter:description" content="还是要经常折腾一下  最近稍微折腾了一下vim，大家都知道linux环境下如果vim操作的足够熟练，完全可以替代各种文本编辑器，然而自己对vim的操作仍停留在最原始和基础的命令，只会简单的增删改查，比如删除d，进入编辑模式i，复制粘贴y&amp;amp;p，代码上下翻阅左右箭头，看到这你估计都惊呆了，怎么这么low!也是由于近期经常需要到仿真机上修改代码，发现自己vim编辑效率超级低，这才想着好好过一遍">
<meta name="twitter:image" content="https://raw.githubusercontent.com/upeng/upeng.github.io/master/image/vim-keyboard.png">
  
    <link rel="alternate" href="/atom.xml" title="Taylor&#39;s Learning Diary" type="application/atom+xml">
  
  
    <link rel="icon" href="/favicon.png">
  
  
    <link href="//fonts.googleapis.com/css?family=Source+Code+Pro" rel="stylesheet" type="text/css">
  
  <link rel="stylesheet" href="/blog/css/style.css">
  

</head>

<body>
  <div id="container">
    <div id="wrap">
      <header id="header">
  <div id="banner"></div>
  <div id="header-outer" class="outer">
    <div id="header-title" class="inner">
      <h1 id="logo-wrap">
        <a href="/blog/" id="logo">Taylor&#39;s Learning Diary</a>
      </h1>
      
    </div>
    <div id="header-inner" class="inner">
      <nav id="main-nav">
        <a id="main-nav-toggle" class="nav-icon"></a>
        
          <a class="main-nav-link" href="/blog/">Home</a>
        
          <a class="main-nav-link" href="/blog/archives">Archives</a>
        
      </nav>
      <nav id="sub-nav">
        
          <a id="nav-rss-link" class="nav-icon" href="/atom.xml" title="RSS Feed"></a>
        
        <a id="nav-search-btn" class="nav-icon" title="搜索"></a>
      </nav>
      <div id="search-form-wrap">
        <form action="//google.com/search" method="get" accept-charset="UTF-8" class="search-form"><input type="search" name="q" class="search-form-input" placeholder="Search"><button type="submit" class="search-form-submit">&#xF002;</button><input type="hidden" name="sitesearch" value="https://upeng.github.io/blog"></form>
      </div>
    </div>
  </div>
</header>
      <div class="outer">
        <section id="main"><article id="post-vim" class="article article-type-post" itemscope itemprop="blogPost">
  <div class="article-meta">
    <a href="/blog/2016/09/11/vim/" class="article-date">
  <time datetime="2016-09-11T15:05:25.000Z" itemprop="datePublished">2016-09-11</time>
</a>
    
  <div class="article-category">
    <a class="article-category-link" href="/blog/categories/Linux/">Linux</a>
  </div>

  </div>
  <div class="article-inner">
    
    
      <header class="article-header">
        
  
    <h1 class="article-title" itemprop="name">
      vim学习笔记
    </h1>
  

      </header>
    
    <div class="article-entry" itemprop="articleBody">
      
        <blockquote>
<p>还是要经常折腾一下</p>
</blockquote>
<p>最近稍微折腾了一下vim，大家都知道linux环境下如果vim操作的足够熟练，完全可以替代各种文本编辑器，然而自己对vim的操作仍停留在最原始和基础的命令，只会简单的增删改查，比如删除d，进入编辑模式i，复制粘贴y&amp;p，代码上下翻阅左右箭头，看到这你估计都惊呆了，怎么这么low!也是由于近期经常需要到仿真机上修改代码，发现自己vim编辑效率超级低，这才想着好好过一遍vim指令，提高逼格！^_^</p>
<h3 id="vim配置文件-vimrc"><a href="#vim配置文件-vimrc" class="headerlink" title="vim配置文件.vimrc"></a><a href="#vim配置文件-vimrc" title="vim配置文件.vimrc"></a>vim配置文件.vimrc</h3><p>这个文件是vim的配置文件，在这里配置一下全局生效，更加丰富的配置后续逐步学习</p>
<ol>
<li>比如之前每次查代码行数都要 <code>:set nu</code>，如果写在.vimrc就不用每次都<code>:set nu</code>了。</li>
<li>比如写完一行代码enter换行后，又从头再来，必须手动tab缩进。。。</li>
</ol>
<figure class="highlight applescript"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div></pre></td><td class="code"><pre><div class="line"><span class="keyword">set</span> <span class="built_in">number</span> <span class="comment"># 显示行号</span></div><div class="line"><span class="keyword">set</span> autoindent <span class="comment"># 自动缩进</span></div></pre></td></tr></table></figure>
<a id="more"></a>
<h3 id="vim模式"><a href="#vim模式" class="headerlink" title="vim模式"></a><a href="#vim模式" title="vim模式"></a>vim模式</h3><p>我们知道vim的模式【insert模式、普通模式、visual模式】中<strong>insert模式</strong>和<strong>visual模式</strong>是不能直接互跳的，必须先返回到<strong>普通模式</strong>！普通模式下<code>:</code>进入命令模式<br>快速进入insert模式：普通模式下输入 i/o/a，esc返回到普通模式<br>快速进入visual模式：普通模式下输入 v，再次v返回到普通模式</p>
<h3 id="普通模式下快速跳转"><a href="#普通模式下快速跳转" class="headerlink" title="普通模式下快速跳转"></a><a href="#普通模式下快速跳转" title="普通模式下快速跳转"></a>普通模式下快速跳转</h3><p>不要只会箭头上下左右了！这个能提高效率</p>
<figure class="highlight mipsasm"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div></pre></td><td class="code"><pre><div class="line">gg(<span class="number">1</span>G)  <span class="comment"># 文件顶部 </span></div><div class="line">G     <span class="comment"># 文件尾部</span></div><div class="line">control + [    <span class="comment"># 向上片段移动</span></div><div class="line">control + ] <span class="comment"># 向下片段移动 </span></div><div class="line"><span class="keyword">j </span><span class="comment"># 下一行</span></div><div class="line">k <span class="comment"># 上一行</span></div><div class="line">w <span class="comment"># 下一个单词</span></div><div class="line"><span class="keyword">b </span><span class="comment"># 上一个单词</span></div></pre></td></tr></table></figure>
<h3 id="复制粘贴一块代码"><a href="#复制粘贴一块代码" class="headerlink" title="复制粘贴一块代码"></a><a href="#复制粘贴一块代码" title="复制粘贴一块代码"></a>复制粘贴一块代码</h3><ol>
<li>按Esc切换到正常模式；</li>
<li>把光标移到你需要复制的代码行首；</li>
<li>按V选择整行，可移动光标选择多行；</li>
<li>按d剪切或按y复制选择的代码；</li>
<li>移动光标到你需要粘贴的位置，按p粘贴代码到光标后的位置，或按P粘贴到光标前。</li>
</ol>
<h3 id="删除"><a href="#删除" class="headerlink" title="删除"></a><a href="#删除" title="删除"></a>删除</h3><blockquote>
<p>下面命令必须先将鼠标移动到指定位置或指定行</p>
</blockquote>
<ul>
<li>字母<code>x</code> 删除当前定位的字母</li>
<li><code>dw</code> 删除当前鼠标所在的单词 <code>db</code>向前删除一个单词</li>
<li><code>5dd</code>删除从当前行开始（包括当前行在内）的5行</li>
<li><code>dG</code> 输入<code>d</code>，然后<code>shift+g</code>(或大写<code>G</code>)</li>
<li>删除21-94行之间的内容，鼠标在第10行，如何快速删除！记住！总是忘记！<code>:21,94d</code></li>
</ul>
<h3 id="命令模式"><a href="#命令模式" class="headerlink" title="命令模式"></a><a href="#命令模式" title="命令模式"></a>命令模式</h3><p>普通模式下<code>/</code>搜索，n下一个，N上一个<br>普通模式下<code>:e filepath/file</code>打开file<br>批量替换<code>:%s/word1/word2/g</code><br>复制一个文件全部内容到当前文件的指定位置<code>:read filepath/file</code></p>
<h3 id="撤销或重做"><a href="#撤销或重做" class="headerlink" title="撤销或重做"></a><a href="#撤销或重做" title="撤销或重做"></a>撤销或重做</h3><p><code>u</code>撤销，<code>ctrl+r</code>重做（像sublime的cmd+y）</p>
<h3 id="快速进入insert模式"><a href="#快速进入insert模式" class="headerlink" title="快速进入insert模式"></a><a href="#快速进入insert模式" title="快速进入insert模式"></a>快速进入insert模式</h3><p>普通模式下，随处都可以进入编辑模式，可能之前你只注意到<code>i</code>命令，其实还有两个<strong>非常实用</strong>的命令<code>a</code>和<code>o</code><br><code>a</code>–从当前鼠标定位开始,立刻可编辑<br><code>o</code>–立刻换行编辑</p>
<h3 id="代码注释"><a href="#代码注释" class="headerlink" title="代码注释"></a><a href="#代码注释" title="代码注释"></a>代码注释</h3><blockquote>
<p>代码注释：</p>
</blockquote>
<ul>
<li>按v切换到可视化模式；</li>
<li>移动光标(j或k)选中需要注释的行的开头；</li>
<li>按大写I，然后输入注释符，如#；</li>
<li>最后按Esc。</li>
</ul>
<blockquote>
<p>取消注释：</p>
</blockquote>
<ul>
<li>按Ctrl+v切换到可视化模式；</li>
<li>按j或k选择要删除的注释符；</li>
<li>按d或x删除注释符</li>
</ul>
<p>通过学习，效率有所提高，但vim更加丰富的功能还需要进一步探索，计划上面的命令使用非常熟练自如后再进行第二阶段的学习和探索–命令模式和目录可视化的打造。</p>
<h3 id="vim键盘图"><a href="#vim键盘图" class="headerlink" title="vim键盘图"></a><a href="#vim键盘图" title="vim键盘图"></a>vim键盘图</h3><p><img src="https://raw.githubusercontent.com/upeng/upeng.github.io/master/image/vim-keyboard.png" alt="vim-keyboard"></p>
<h3 id="参考文章"><a href="#参考文章" class="headerlink" title="参考文章"></a><a href="#参考文章" title="参考文章"></a>参考文章</h3><p><a href="https://www.shiyanlou.com/questions/3176" target="_blank" rel="external">https://www.shiyanlou.com/questions/3176</a><br><a href="http://harttle.com/2015/11/07/vim-cursor.html" target="_blank" rel="external">http://harttle.com/2015/11/07/vim-cursor.html</a></p>

      
    </div>
    <footer class="article-footer">
      <a data-url="https://upeng.github.io/blog/2016/09/11/vim/" data-id="cj8x781ao0047gwp4yslx6edc" class="article-share-link">Share</a>
      
        <a href="https://upeng.github.io/blog/2016/09/11/vim/#disqus_thread" class="article-comment-link">留言</a>
      
      
  <ul class="article-tag-list"><li class="article-tag-list-item"><a class="article-tag-list-link" href="/blog/tags/linux/">linux</a></li><li class="article-tag-list-item"><a class="article-tag-list-link" href="/blog/tags/vim/">vim</a></li></ul>

    </footer>
  </div>
  
    
<nav id="article-nav">
  
    <a href="/blog/2016/10/11/publish-laravel-package/" id="article-nav-newer" class="article-nav-link-wrap">
      <strong class="article-nav-caption">Newer</strong>
      <div class="article-nav-title">
        
          从编写到发布laravel扩展
        
      </div>
    </a>
  
  
    <a href="/blog/2016/08/28/mac-lnmp/" id="article-nav-older" class="article-nav-link-wrap">
      <strong class="article-nav-caption">Older</strong>
      <div class="article-nav-title">Mac下安装LNMP(Nginx+PHP5.6)环境</div>
    </a>
  
</nav>

  
</article>


<section id="comments">
  <div id="disqus_thread">
    <noscript>Please enable JavaScript to view the <a href="//disqus.com/?ref_noscript">comments powered by Disqus.</a></noscript>
  </div>
</section>
</section>
        
          <aside id="sidebar">
  
    
  <div class="widget-wrap">
    <h3 class="widget-title">分类</h3>
    <div class="widget">
      <ul class="category-list"><li class="category-list-item"><a class="category-list-link" href="/blog/categories/Linux/">Linux</a><span class="category-list-count">8</span></li><li class="category-list-item"><a class="category-list-link" href="/blog/categories/MySQL/">MySQL</a><span class="category-list-count">6</span></li><li class="category-list-item"><a class="category-list-link" href="/blog/categories/PHP/">PHP</a><span class="category-list-count">15</span></li><li class="category-list-item"><a class="category-list-link" href="/blog/categories/Thinking/">Thinking</a><span class="category-list-count">1</span></li><li class="category-list-item"><a class="category-list-link" href="/blog/categories/其他/">其他</a><span class="category-list-count">8</span></li><li class="category-list-item"><a class="category-list-link" href="/blog/categories/前端/">前端</a><span class="category-list-count">2</span></li><li class="category-list-item"><a class="category-list-link" href="/blog/categories/数据库范式/">数据库范式</a><span class="category-list-count">1</span></li></ul>
    </div>
  </div>


  
    
  <div class="widget-wrap">
    <h3 class="widget-title">标签云</h3>
    <div class="widget tagcloud">
      <a href="/blog/tags/CI/" style="font-size: 10px;">CI</a> <a href="/blog/tags/JQuery/" style="font-size: 10px;">JQuery</a> <a href="/blog/tags/Mac/" style="font-size: 13.33px;">Mac</a> <a href="/blog/tags/MySQL/" style="font-size: 10px;">MySQL</a> <a href="/blog/tags/awk/" style="font-size: 10px;">awk</a> <a href="/blog/tags/bash/" style="font-size: 10px;">bash</a> <a href="/blog/tags/composer/" style="font-size: 10px;">composer</a> <a href="/blog/tags/eloquent/" style="font-size: 10px;">eloquent</a> <a href="/blog/tags/hexo/" style="font-size: 10px;">hexo</a> <a href="/blog/tags/idempotence/" style="font-size: 10px;">idempotence</a> <a href="/blog/tags/item/" style="font-size: 10px;">item</a> <a href="/blog/tags/laravel/" style="font-size: 20px;">laravel</a> <a href="/blog/tags/linux/" style="font-size: 16.67px;">linux</a> <a href="/blog/tags/mac/" style="font-size: 10px;">mac</a> <a href="/blog/tags/memcacheq/" style="font-size: 10px;">memcacheq</a> <a href="/blog/tags/mysql/" style="font-size: 16.67px;">mysql</a> <a href="/blog/tags/nc/" style="font-size: 10px;">nc</a> <a href="/blog/tags/packageist/" style="font-size: 10px;">packageist</a> <a href="/blog/tags/php/" style="font-size: 13.33px;">php</a> <a href="/blog/tags/sed/" style="font-size: 10px;">sed</a> <a href="/blog/tags/shell/" style="font-size: 10px;">shell</a> <a href="/blog/tags/static/" style="font-size: 10px;">static</a> <a href="/blog/tags/thinking/" style="font-size: 13.33px;">thinking</a> <a href="/blog/tags/tmux/" style="font-size: 10px;">tmux</a> <a href="/blog/tags/vagrant/" style="font-size: 10px;">vagrant</a> <a href="/blog/tags/validator/" style="font-size: 10px;">validator</a> <a href="/blog/tags/vim/" style="font-size: 10px;">vim</a> <a href="/blog/tags/vuejs/" style="font-size: 10px;">vuejs</a> <a href="/blog/tags/zephir/" style="font-size: 10px;">zephir</a> <a href="/blog/tags/zsh/" style="font-size: 10px;">zsh</a> <a href="/blog/tags/设计模式/" style="font-size: 13.33px;">设计模式</a>
    </div>
  </div>

  
    
  <div class="widget-wrap">
    <h3 class="widget-title">归档</h3>
    <div class="widget">
      <ul class="archive-list"><li class="archive-list-item"><a class="archive-list-link" href="/blog/archives/2017/10/">十月 2017</a><span class="archive-list-count">1</span></li><li class="archive-list-item"><a class="archive-list-link" href="/blog/archives/2017/09/">九月 2017</a><span class="archive-list-count">4</span></li><li class="archive-list-item"><a class="archive-list-link" href="/blog/archives/2016/12/">十二月 2016</a><span class="archive-list-count">4</span></li><li class="archive-list-item"><a class="archive-list-link" href="/blog/archives/2016/11/">十一月 2016</a><span class="archive-list-count">1</span></li><li class="archive-list-item"><a class="archive-list-link" href="/blog/archives/2016/10/">十月 2016</a><span class="archive-list-count">2</span></li><li class="archive-list-item"><a class="archive-list-link" href="/blog/archives/2016/09/">九月 2016</a><span class="archive-list-count">1</span></li><li class="archive-list-item"><a class="archive-list-link" href="/blog/archives/2016/08/">八月 2016</a><span class="archive-list-count">3</span></li><li class="archive-list-item"><a class="archive-list-link" href="/blog/archives/2016/07/">七月 2016</a><span class="archive-list-count">2</span></li><li class="archive-list-item"><a class="archive-list-link" href="/blog/archives/2016/06/">六月 2016</a><span class="archive-list-count">3</span></li><li class="archive-list-item"><a class="archive-list-link" href="/blog/archives/2016/05/">五月 2016</a><span class="archive-list-count">4</span></li><li class="archive-list-item"><a class="archive-list-link" href="/blog/archives/2016/04/">四月 2016</a><span class="archive-list-count">7</span></li><li class="archive-list-item"><a class="archive-list-link" href="/blog/archives/2016/02/">二月 2016</a><span class="archive-list-count">1</span></li><li class="archive-list-item"><a class="archive-list-link" href="/blog/archives/2016/01/">一月 2016</a><span class="archive-list-count">2</span></li><li class="archive-list-item"><a class="archive-list-link" href="/blog/archives/2015/10/">十月 2015</a><span class="archive-list-count">3</span></li><li class="archive-list-item"><a class="archive-list-link" href="/blog/archives/2015/08/">八月 2015</a><span class="archive-list-count">2</span></li><li class="archive-list-item"><a class="archive-list-link" href="/blog/archives/2015/07/">七月 2015</a><span class="archive-list-count">1</span></li></ul>
    </div>
  </div>


  
    
  <div class="widget-wrap">
    <h3 class="widget-title">最新文章</h3>
    <div class="widget">
      <ul>
        
          <li>
            <a href="/blog/2017/10/18/laravel-validator/">Laravel Validator自定义参数验证规则</a>
          </li>
        
          <li>
            <a href="/blog/2017/09/28/linux-sed/">linux常用命令之sed</a>
          </li>
        
          <li>
            <a href="/blog/2017/09/27/shell-script-learning/">shell脚本由点到面学习总结</a>
          </li>
        
          <li>
            <a href="/blog/2017/09/14/laravel-eloquent-index/">Eloquent ORM多个and和or条件查询</a>
          </li>
        
          <li>
            <a href="/blog/2017/09/10/Linux压缩解压缩命令-index/">Linux常用压缩解压缩命令</a>
          </li>
        
      </ul>
    </div>
  </div>

  
</aside>
        
      </div>
      <footer id="footer">
  
  <div class="outer">
    <div id="footer-info" class="inner">
      &copy; 2017 Tayloryu<br>
      Powered by <a href="http://hexo.io/" target="_blank">Hexo</a>
    </div>
  </div>
</footer>
    </div>
    <nav id="mobile-nav">
  
    <a href="/blog/" class="mobile-nav-link">Home</a>
  
    <a href="/blog/archives" class="mobile-nav-link">Archives</a>
  
</nav>
    
<script>
  var disqus_shortname = 'tayloryu';
  
  var disqus_url = 'https://upeng.github.io/blog/2016/09/11/vim/';
  
  (function(){
    var dsq = document.createElement('script');
    dsq.type = 'text/javascript';
    dsq.async = true;
    dsq.src = '//' + disqus_shortname + '.disqus.com/embed.js';
    (document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0]).appendChild(dsq);
  })();
</script>


<script src="//ajax.googleapis.com/ajax/libs/jquery/2.0.3/jquery.min.js"></script>


  <link rel="stylesheet" href="/blog/fancybox/jquery.fancybox.css">
  <script src="/blog/fancybox/jquery.fancybox.pack.js"></script>


<script src="/blog/js/script.js"></script>
  </div>
</body>
</html>